<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <canvas id="canvas" width="400" height="400">
        此浏览器不支持canvas
    </canvas>
</body>
</html>
<script>
    const ctx = document.getElementById('canvas')
    const gl = ctx.getContext('webgl')

    //gl.clearColor(r,g,b,a)指定清空<canvas>的颜色，接受4个参数（取值区间为0.0~1.）
    gl.clearColor(1.0, 0.0, 0.0, 1.0)
    //gl.clear(buffer)清空canvas参数分别为三项
    //gl.COLOR_BUFFER_BIT 清空颜色缓存
    //gl.DEPTH_BUFFER_BIT 清空深度缓冲区
    //gl.STENCIL_BUFFER_BIT 清空模板缓冲区

    //gl.clear(gl.COLOR_BUFFER_BIT)和gl.clearColor(0.0, 0.0, 0.0, 1.0)
    //gl.clear(gl.DEPTH_BUFFER_BIT)和gl.clearDepth(1.0)
    //gl.clear(gl.STENCIL_BUFFER_BIT)和gl.clearStencil(0)
    gl.clear(gl.COLOR_BUFFER_BIT)
</script>